package day02;
//类型间转换的演示
public class DataTypeCastDemo {
    public static void main(String[] args) {
        //两种方式: 自动类型转换, 强制类型转换
        /*
        int a = 5;
        long b = a; //自动类型转换
        int c = (int)b; //强制类型转换

        long d = 5; //自动类型转换
        double e = 5; //自动类型转换
        System.out.println(e); //5.0 默认保留一位小数

        long f = 10000000000L;
        int g = (int)f;
        System.out.println(g); //1410065408, 强转有可能发生溢出
        double h = 25.987;
        int i = (int)h;
        System.out.println(i); //25, 强转有可能丢失精度
        */

        //两点规则:
        byte b1 = 5; //5为整数直接量
        byte b2 = 6;
        byte b3 = (byte)(b1+b2);

        System.out.println(2+2);    //4
        System.out.println(2+'2');  //52, 2加上'2'的码50
        System.out.println('2'+'2'); //100. '2'的码50. 加上'2'的码50
        System.out.println('2');    //2. 因为没有运算, 所以输出的是字符2

        int m = 'a';
        System.out.println(m);  //97, 查看字符对应的码
        char n = 97;
        System.out.println(n);  //a. 查看码对应的字符

        //-----------------------------------------------------------------

        //第二遍
        /*
        byte b1 = 5;
        byte b2 = 6;
        byte b3 = (byte)(b1+b2);

        System.out.println(2+2);
        System.out.println(2+'2');
        System.out.println('2'+'2');
        System.out.println('2');

        int m = 'a';
        System.out.println(m);
        char n = 97;
        System.out.println(n);
        */

        //第三遍
        /*
        byte b1 = 5;
        byte b2 = 6;
        byte b3 = (byte)(b1+b2);

        System.out.println(2+2);
        System.out.println(2+'2');
        System.out.println('2'+'2');
        System.out.println('2');

        int m = 'a';
        System.out.println(m);
        char n = 97;
        System.out.println(n);
        */

        //第四遍
        /*
        byte b1 = 5;
        byte b2 = 6;
        byte b3 = (byte)(b1+b2);

        System.out.println(2+2);
        System.out.println(2+'2');
        System.out.println('2'+'2');
        System.out.println('2');

        int m = 'a';
        System.out.println(m);
        char n = 97;
        System.out.println(n);
        */

        //-----------------------------------------------------------------

        //第二遍
        /*
        int a = 5;
        long b = a;
        int c = (int)b;

        long d = 5;
        double e = 5;
        System.out.println(e);

        long f = 10000000000L;
        int g = (int)f;
        System.out.println(g);
        double h = 25.987;
        int i = (int)h;
        System.out.println(i);
        */

        //第三遍
        /*
        int a = 5;
        long b = a;
        int c = (int)b;

        long d = 5;
        double e = 5;
        System.out.println(e);

        long f = 10000000000L;
        int g = (int)f;
        System.out.println(g);
        double h = 25.987;
        int i = (int)h;
        System.out.println(i);
         */
    }
}
